package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.system.domain.YyHospitalDepartment;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IYyHospitalDepartmentService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 科室Controller
 *
 * @author ruoyi
 * @date 2025-03-25
 */
@Controller
@RequestMapping("/system/department")
public class YyHospitalDepartmentController extends BaseController
{
    private String prefix = "system/department";

    @Autowired
    private IYyHospitalDepartmentService yyHospitalDepartmentService;

    @RequiresPermissions("system:department:view")
    @GetMapping()
    public String department()
    {
        return prefix + "/department";
    }

    /**
     * 查询科室列表
     */
    @RequiresPermissions("system:department:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YyHospitalDepartment yyHospitalDepartment)
    {
        startPage();
        List<YyHospitalDepartment> list = yyHospitalDepartmentService.selectYyHospitalDepartmentList(yyHospitalDepartment);
        return getDataTable(list);
    }

    /**
     * 导出科室列表
     */
    @RequiresPermissions("system:department:export")
    @Log(title = "科室", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YyHospitalDepartment yyHospitalDepartment)
    {
        List<YyHospitalDepartment> list = yyHospitalDepartmentService.selectYyHospitalDepartmentList(yyHospitalDepartment);
        ExcelUtil<YyHospitalDepartment> util = new ExcelUtil<YyHospitalDepartment>(YyHospitalDepartment.class);
        return util.exportExcel(list, "科室数据");
    }

    /**
     * 新增科室
     */
    @RequiresPermissions("system:department:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存科室
     */
    @RequiresPermissions("system:department:add")
    @Log(title = "科室", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YyHospitalDepartment yyHospitalDepartment)
    {
        return toAjax(yyHospitalDepartmentService.insertYyHospitalDepartment(yyHospitalDepartment));
    }

    /**
     * 修改科室
     */
    @RequiresPermissions("system:department:edit")
    @GetMapping("/edit/{departmentId}")
    public String edit(@PathVariable("departmentId") Long departmentId, ModelMap mmap)
    {
        YyHospitalDepartment yyHospitalDepartment = yyHospitalDepartmentService.selectYyHospitalDepartmentByDepartmentId(departmentId);
        mmap.put("yyHospitalDepartment", yyHospitalDepartment);
        return prefix + "/edit";
    }

    /**
     * 修改保存科室
     */
    @RequiresPermissions("system:department:edit")
    @Log(title = "科室", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YyHospitalDepartment yyHospitalDepartment)
    {
        return toAjax(yyHospitalDepartmentService.updateYyHospitalDepartment(yyHospitalDepartment));
    }

    /**
     * 删除科室
     */
    @RequiresPermissions("system:department:remove")
    @Log(title = "科室", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(yyHospitalDepartmentService.deleteYyHospitalDepartmentByDepartmentIds(ids));
    }
}
